package com.zofer.study;

import java.util.concurrent.Semaphore;

public class SemaphoreTest {

    static Semaphore semaphore = new Semaphore(3);

    static class TestThread implements Runnable{
        @Override
        public void run() {
            try {
                semaphore.acquire();
                System.out.println(Thread.currentThread().getName()+"正在执行...");
                Thread.sleep(1);
                System.out.println(Thread.currentThread().getName()+"执行完了");
                semaphore.release();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10 ; i++) {
            Thread t1 = new Thread(new TestThread());
            t1.start();
        }
    }
}
